﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace RhythmComet.Physics
{
    public static class PhysicsHelper
    {
        public static float FuncaoEspaco(float So, float Vo, float a, float t)
        {
            return (float)(So + (Vo * t) + (a * Math.Pow(t, 2.0f) / 2.0f));
        }

        public static float Torricelli(float Vo, float a, float deltaS)
        {
            return (float)(Math.Sqrt(Math.Pow(Vo, 2.0f) + (2.0f * a * deltaS)));
        }

        public static float FuncaoVelocidade(float Vo, float a, float t)
        {
            return (float)(Vo + (a * t));
        }

        public static Vector2 Direcao(Vector2 start, Vector2 end)
        {
            return new Vector2(end.X - start.X, end.Y - start.Y);
        }

        public static float NormaR2(Vector2 vector)
        {
            return (float)(Math.Sqrt(Math.Pow(vector.X, 2) + Math.Pow(vector.Y, 2)));
        }

        public static float NormaR3(Vector3 vector)
        {
            return (float)(Math.Sqrt(Math.Pow(vector.X, 2) + Math.Pow(vector.Y, 2) + Math.Pow(vector.Z, 2)));
        }

        public static Vector2 NormalizaR2(Vector2 vector)
        {
            Vector2 normalizado = Vector2.Zero;
            if (vector != Vector2.Zero)
            {
                float norma = NormaR2(vector);
                normalizado = new Vector2(vector.X / norma, vector.Y / norma);
            }
            return normalizado;
        }

        public static Vector3 NormalizaR3(Vector3 vector)
        {
            Vector3 normalizado = Vector3.Zero;
            if (vector != Vector3.Zero)
            {
                float norma = NormaR3(vector);
                normalizado = new Vector3(vector.X / norma, vector.Y / norma, vector.Z / norma);
            }
            return normalizado;
        }
    }
}
